package com.lz.football.module.friend.item
{
	import com.common.utils.Reflection;
	import com.liangzhong.constants.ClubConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.FriendEvent;
	import com.liangzhong.model.AppData;
	import com.liangzhong.model.friend.vo.FriendInfoVo;
	import com.liangzhong.model.friend.vo.FriendVo;
	import com.lz.football.module.club.item.BaseItem;
	
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.ColorMatrixFilter;
	import flash.text.TextField;
	
	/**
	 *准好友ITEm 
	 * @author Administrator
	 * 
	 */	
	public class FriendGrantItem extends BaseItem
	{
		/**
		 * 
		 */
		private var vip:TextField;
		/**
		 *名称  
		 */
		private var playerName:TextField;
		/**
		 *国家 
		 */
		private var country:TextField;
		/**
		 *等级  
		 */
		private var Lv:TextField;
		/**
		 *综合能力 
		 */
		private var ability:TextField;
		/**
		 *时间 
		 */
		private var time:TextField;
		/**
		 *接受按钮 
		 */
		private var agreeBtn:SimpleButton;
		/**
		 *拒绝按钮 
		 */
		private var refuseBtn:SimpleButton;
		
		/**
		 *添加好友按钮 
		 */
		private var addBtn:SimpleButton;
		/**
		 * 背景 
		 */
		private var listBg:MovieClip;
		private var _type:int;
		private var _invitestatus:Boolean;
		private var _friendId:int;
		public function FriendGrantItem()
		{
			super();
		}
		override public function initUI(view:Object=null):void
		{
			_skin = Reflection.createInstance("com.football.module.friend.addFriendItem");
			this.addChild(_skin);
			
			vip = _skin.vip;
//			vip.mouseChildren = false;
			vip.mouseEnabled =false;
			playerName = _skin.playerName;
			playerName.mouseEnabled = false;
			country = _skin.country;
			Lv = _skin.Lv;
			ability = _skin.ability;
			time =_skin.time;
			agreeBtn = _skin.agreeBtn;
			refuseBtn = _skin.refuseBtn;
			addBtn = _skin.addBtn;
			listBg = _skin.listBg;
			_skin.frame.mouseChildren = false;
			_skin.frame.mouseEnabled = false;
			country.mouseEnabled = false;
			Lv.mouseEnabled = false;
			ability.mouseEnabled = false;
			time.mouseEnabled = false;
			super.initUI();
			reset();
		}
		/**
		 * 
		 * 
		 */
		override public function addEvtListener():void
		{
			super.addEvtListener();
			agreeBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			refuseBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			addBtn.addEventListener(MouseEvent.CLICK,onClickHandler);
			if(_skin != null)_skin.removeEventListener(MouseEvent.CLICK,onMouseClick);
			listBg.addEventListener(MouseEvent.CLICK,onMouseClick);
			AppEventDispatcher.getInstance().addEventListener(FriendEvent.GET_LOOK_UP_INFO,onLookUpHandler);
		}
		
		/**
		 *查看信息返回 
		 * @param event
		 * 
		 */
		protected function onLookUpHandler(event:Event):void
		{
			// TODO Auto-generated method stub
			this.parent.mouseChildren = true;
			this.parent.mouseEnabled = true;
			//			listBg.addEventListener(MouseEvent.CLICK,onMouseClick);
		}
		/**
		 * 点击 
		 * @param event
		 * 
		 */		
		override public function onMouseClick(event:MouseEvent):void
		{
			super.onMouseClick(event);
			//			trace("查看消息");
			if(data == null)return;
			var f:FriendInfoVo = new FriendInfoVo();
			f.friendid = data.friendid;
			this.parent.mouseChildren = false;
			this.parent.mouseEnabled = false;
			//			listBg.removeEventListener(MouseEvent.CLICK,onMouseClick);
			AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.LOOK_UP_FRIEND,{vo:f}));
		}
		protected function onClickHandler(event:MouseEvent):void
		{
			//			trace("+++++++++++");
			switch(event.target)
			{
				case agreeBtn:
					//					trace("名称-->" + vo.uname + "-->"+vo.friendid);
					AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.AGGREE_INVITE,{arr:[_friendId]}));
					break;
				case refuseBtn:
					AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.REFUSE_INVITE,{id:_friendId}));
					break;
				case addBtn:
					//					trace("名称-->" + vo.uname + "-->"+vo.friendid);
					invitestatus = true;
					AppEventDispatcher.getInstance().dispatchEvent(new FriendEvent(FriendEvent.INVITE_FRIENDS,{array:[_friendId]}));
					break;
			}
		}
		/**
		 *重置 
		 * 
		 */
		override public function reset():void
		{
			super.reset();
//			vip.visible = false;
			playerName.text = "";
			country.text = "";
			Lv.text = "";
			ability.text = "";
			time.text = "";
			vip.text = "";
			agreeBtn.visible = false;
			refuseBtn.visible = false;
			addBtn.visible = false;
//			vip.textColor = 0x000000
			playerName.textColor = 0x000000
			Lv.textColor =0x000000;
			vip.textColor = 0x245B9C
			data = null;
		}
		private var vo:FriendVo;
		override public function set data(value:Object):void
		{
			super.data = value;
			if(value == null)return;
			type = _type;
			var friendVo:FriendVo = value as FriendVo;
			vo = friendVo;
			_friendId = friendVo.friendid;
//			vip.gotoAndStop(1);
			
			if(friendVo.VIP > 0)
				vip.text = "VIP" + friendVo.VIP;
			playerName.text = friendVo.uname + "";
			country.text = ClubConst.countryToString(friendVo.country)+ "";
			Lv.text = "" + friendVo.level;
			ability.text = friendVo.ability + "";
			time.text = "" + friendVo.time_str ;
			if(friendVo.VIP > 0)
				vip.visible = true;
//			vip.text = "VIP9";
			playerName.textColor = 0xCCCCCC
			country.textColor = 0xCCCCCC
			Lv.textColor =0xCCCCCC
			ability.textColor = 0xCCCCCC
			time.textColor = 0xCCCCCC
			vip.textColor =0xCCCCCC;
		}
		
		/**
		 *类型 1为邀请，2为系统消息添加好友 
		 */
		public function get type():int
		{
			return _type;
		}
		
		/**
		 * @private
		 */
		public function set type(value:int):void
		{
			_type = value;
			switch(_type)
			{
				case 1:
					agreeBtn.visible = true;
					refuseBtn.visible = true;
					break;
				case 2:
					addBtn.visible = true;
					break;
			}
			
		}
		
		/**
		 *邀请状态 
		 * 邀请过的为true;
		 * 按钮变灰
		 */
		public function get invitestatus():Boolean
		{
			return _invitestatus;
		}
		
		/**
		 * @private
		 */
		public function set invitestatus(value:Boolean):void
		{
			_invitestatus = value;
			if(_invitestatus)
			{
				addBtn.filters = [new ColorMatrixFilter([0.5,0.5,0.5,0,0,
					0.5,0.5,0.5,0,0,
					0.5,0.5,0.5,0,0,
					0,0,0,1,0,])];
				addBtn.mouseEnabled = false;
				
			}else
			{
				addBtn.filters =null;
				addBtn.mouseEnabled = true;;
			}
			
		}
		
		/**
		 *好友ID（好友俱乐部ID） 
		 */
		public function get friendId():int
		{
			return _friendId;
		}
		
		/**
		 * @private
		 */
		public function set friendId(value:int):void
		{
			_friendId = value;
		}
		override public function removeEvtListener():void
		{
			super.removeEvtListener();
			agreeBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			refuseBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			addBtn.removeEventListener(MouseEvent.CLICK,onClickHandler);
			if(_skin!= null)_skin.removeEventListener(MouseEvent.CLICK,onMouseClick);
			listBg.removeEventListener(MouseEvent.CLICK,onMouseClick);
			AppEventDispatcher.getInstance().removeEventListener(FriendEvent.GET_LOOK_UP_INFO,onLookUpHandler);
		}
		override public function destroyView():void
		{
			removeEvtListener();
			_skin = null;
			super.destroyView();
		}
		/**
		 * 移出 
		 * @param event
		 * 
		 */
		override public function onMouseRollOut(event:MouseEvent):void
		{
			super.onMouseRollOut(event);
			playerName.textColor = 0xCCCCCC
			country.textColor = 0xCCCCCC
			Lv.textColor =0xCCCCCC
			ability.textColor = 0xCCCCCC
			time.textColor = 0xCCCCCC
			vip.textColor = 0x2CCCCCC;
		}
		
		/**
		 * 移上 
		 * @param event
		 * 
		 */
		override public function onMouseRollOver(event:MouseEvent):void
		{
			super.onMouseRollOver(event);
			playerName.textColor = 0xFFFFFF;
			country.textColor = 0xFFFFFF;
			Lv.textColor = 0xFFFFFF;
			ability.textColor = 0xFFFFFF;
			time.textColor = 0xFFFFFF;
			vip.textColor = 0xFFCC00;
		}
		
	}
	
	
}